<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_bdcenter extends Controller_Abstract {
	
	/**
	 * 客户端顶部广告
	 */
	function actionIndex()
	{
		$this->union_table = Acctuser::meta();		
		$this->lists(array('is_bd'=>1));
	}
	 
	/**
	 * 修改编辑
	 * @return mixed
	 */
	function actionAdd() {
	    //设置要操作的表单，并设置自动插入方式
	    $this->union_table = Acctuser::meta ();
	    $handle = new helper_autoinsert ( $this->union_table );
	    $form = new Form_bdcenter_add ( url ( $this->_context->controller_name . '/' . $this->_context->action_name ) );
	
	    //这里面会自动将get方式获取的参数传递到表单里面去的
	   
	    if ($this->_context->isGET ()) {
	        $result = $handle->add ( $form, 'id', $_GET );
	        //传递$form值
	        $this->_view ['form'] = $result;
	        $this->_viewname = '../form/add';
	    } else {
	        //记录日志
	        if(!$_POST['id'])	{
	            $acctuser = Acctuser::find('acctname = ?',$_POST['acctname'])->getOne();
	            if(!$acctuser->id()){
	                $this->error('手机号码错误，用户不存在');
	            }else{
	                Acctuser::meta ()->updateWhere(array('is_bd'=>1,'bd_status'=>1),array('acctname'=>$_POST['acctname']));
	                Syslog::logs ( '添加报单中心,id :' . $acctuser->id );
	                $this->success('编辑成功');
	            }
	           
	            
	        }else{
	            $result = $handle->add ( $form, 'id', $_GET );
	            //记录日志
	            Syslog::logs ( '编辑报单中心,id :' . $handle->form_database_obj->id );
	            if($handle->status=='success')  $this->_context->forwardUrl = url("bdcenter/index");
	            return call_user_func_array(array($this,$handle->status),array($result));
	        }
	    }
	}
	
	/**
	 * 删除报单中心
	 */
	function actionDel() {
	     Syslog::logs("删除报单中心，ID：".print_r($this->_context->ids,true));
	     Acctuser::meta()->updateWhere(array('is_bd'=>0,'bd_status'=>0),array('id'=>$this->_context->ids));  
	     $this->success('操作成功');
	}
	
	/**
	 * 报单记录
	 */
	function actionlog(){
	    $this->union_table = bdlog::meta();
	    $this->lists();  
	}

}


